package com.hqyj.util;

import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;

import javax.xml.ws.http.HTTPException;
import java.io.IOException;
import java.util.Random;

public class Phone {
    public String getCode( String phone) throws HTTPException, IOException, com.github.qcloudsms.httpclient.HTTPException {
        String[] num = {phone};
        int appid = 1400494364;
        String appkey = "44ea383ad1fd239541f6dea2f7398465";
        int templateId = 890547; //模板ID
        String smsSign = "rxuan";
        String sources = "0123456789";
        Random rand = new Random();
        StringBuffer flag = new StringBuffer();
        for (int j = 0; j < 6; j++) {
            flag.append(sources.charAt(rand.nextInt(9)) + "");
        }
        String getcodes = flag.toString();
        String[] params = {getcodes}; //短信中的参数
        SmsSingleSender ssender = new SmsSingleSender(appid,appkey);
        SmsSingleSenderResult result = ssender.sendWithParam("86",num[0],templateId,
                params,smsSign,"","");
        System.out.println(result);
        return getcodes;
    }
}
